<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>

	
		<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
		<meta http-equiv="Content-Language" content="en-us">

		<title>Django | Writing your first Django app, part 3 | Django Documentation</title>

		<meta name="ROBOTS" content="ALL">
		<meta http-equiv="imagetoolbar" content="no">
		<meta name="MSSmartTagsPreventParsing" content="true">
		<meta name="Copyright" content="This site's design and contents Copyright (c) 2005  Lawrence Journal-World.">

		<meta name="keywords" content="Python, Django, framework, open-source">
		<meta name="description" content="Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.">

		<link href="Django%20%7C%20Writing%20your%20first%20Django%20app,%20part%203%20%7C%20Django%20Documentation_files/base.css" rel="stylesheet" type="text/css" media="screen">
		<link href="Django%20%7C%20Writing%20your%20first%20Django%20app,%20part%203%20%7C%20Django%20Documentation_files/print.css" rel="stylesheet" type="text/css" media="print">
      
  
  <style type="text/css" media="screen">
    #docs-search {
      color: #000;
      float: right;
    }
    #docs-search form {
      font-size: 92%;
      margin: 0;
      padding: 1em 1em 0;
      white-space: nowrap;
    }
    form.search ul {
      list-style: none;
      margin: 0;
      padding: 0;
    }
    form.search li {
      display: inline;
      padding-right: 1em;
    }
    form.search .query {
      width: 18em;
    }
  </style>
  <link rel="stylesheet" href="Django%20%7C%20Writing%20your%20first%20Django%20app,%20part%203%20%7C%20Django%20Documentation_files/pygments.css" type="text/css">

	</head><body id="documentation" class="default">

	<div id="container">
		<div id="header">
			<h1 id="logo"><a href="http://www.djangoproject.com/"><img src="Django%20%7C%20Writing%20your%20first%20Django%20app,%20part%203%20%7C%20Django%20Documentation_files/hdr_logo.gif" alt="Django"></a></h1>
			<ul id="nav-global">
				<li id="nav-homepage"><a href="http://www.djangoproject.com/">Home</a></li>
				<li id="nav-download"><a href="http://www.djangoproject.com/download/">Download</a></li>
				<li id="nav-documentation"><a href="http://docs.djangoproject.com/">Documentation</a></li>
				<li id="nav-weblog"><a href="http://www.djangoproject.com/weblog/">Weblog</a></li>
				<li id="nav-community"><a href="http://www.djangoproject.com/community/">Community</a></li>
				<li id="nav-code"><a href="http://code.djangoproject.com/">Code</a></li>
			</ul>
		</div>
		<!-- END Header -->
		<div id="billboard">
  <h2><a href="http://docs.djangoproject.com/en/dev/">Django documentation</a></h2>
</div>
		<div id="columnwrap">
			
		<div id="content-main">
		


  <h2 class="deck">
  
    This document is for Django's SVN release, which can be
    significantly different from previous releases. Get old docs here: 
      <a href="http://docs.djangoproject.com/en/1.0/intro/tutorial03/">Django 1.0</a>
  
  </h2>
  <div class="section" id="s-writing-your-first-django-app-part-3">
<span id="s-intro-tutorial03"></span><span id="writing-your-first-django-app-part-3"></span><span id="intro-tutorial03"></span><h1>Writing your first Django app, part 3<a class="headerlink" href="#writing-your-first-django-app-part-3" title="Permalink to this headline">¶</a></h1>
<p>This tutorial begins where <a class="reference external" href="http://docs.djangoproject.com/en/dev/intro/tutorial02/#intro-tutorial02"><em>Tutorial 2</em></a> left off. We’re
continuing the Web-poll application and will focus on creating the public
interface – “views.”</p>
<div class="section" id="s-philosophy">
<span id="philosophy"></span><h2>Philosophy<a class="headerlink" href="#philosophy" title="Permalink to this headline">¶</a></h2>
<p>A view is a “type” of Web page in your Django application that generally serves
a specific function and has a specific template. For example, in a weblog
application, you might have the following views:</p>
<ul class="simple">
<li>Blog homepage – displays the latest few entries.</li>
<li>Entry “detail” page – permalink page for a single entry.</li>
<li>Year-based archive page – displays all months with entries in the
given year.</li>
<li>Month-based archive page – displays all days with entries in the
given month.</li>
<li>Day-based archive page – displays all entries in the given day.</li>
<li>Comment action – handles posting comments to a given entry.</li>
</ul>
<p>In our poll application, we’ll have the following four views:</p>
<ul class="simple">
<li>Poll “archive” page – displays the latest few polls.</li>
<li>Poll “detail” page – displays a poll question, with no results but
with a form to vote.</li>
<li>Poll “results” page – displays results for a particular poll.</li>
<li>Vote action – handles voting for a particular choice in a particular
poll.</li>
</ul>
<p>In Django, each view is represented by a simple Python function.</p>
</div>
<div class="section" id="s-design-your-urls">
<span id="design-your-urls"></span><h2>Design your URLs<a class="headerlink" href="#design-your-urls" title="Permalink to this headline">¶</a></h2>
<p>The first step of writing views is to design your URL structure. You do this by
creating a Python module, called a URLconf. URLconfs are how Django associates
a given URL with given Python code.</p>
<p>When a user requests a Django-powered page, the system looks at the
<a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#setting-ROOT_URLCONF"><tt class="xref docutils literal"><span class="pre">ROOT_URLCONF</span></tt></a> setting, which contains a string in Python dotted
syntax. Django loads that module and looks for a module-level variable called
<tt class="docutils literal"><span class="pre">urlpatterns</span></tt>, which is a sequence of tuples in the following format:</p>
<div class="highlight-python"><pre>(regular expression, Python callback function [, optional dictionary])</pre>
</div>
<p>Django starts at the first regular expression and makes its way down the list,
comparing the requested URL against each regular expression until it finds one
that matches.</p>
<p>When it finds a match, Django calls the Python callback function, with an
<a title="django.http.HttpRequest" class="reference external" href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest"><tt class="xref docutils literal"><span class="pre">HttpRequest</span></tt></a> object as the first argument, any "captured"
values from the regular expression as keyword arguments, and, optionally,
arbitrary keyword arguments from the dictionary (an optional third item in the
tuple).</p>
<p>For more on <a title="django.http.HttpRequest" class="reference external" href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest"><tt class="xref docutils literal"><span class="pre">HttpRequest</span></tt></a> objects, see the
<a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/request-response/#ref-request-response"><em>Request and response objects</em></a>. For more details on URLconfs, see the
<a class="reference external" href="http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-urls"><em>URL dispatcher</em></a>.</p>
<p>When you ran <tt class="docutils literal"><span class="pre">python</span> <span class="pre">django-admin.py</span> <span class="pre">startproject</span> <span class="pre">mysite</span></tt> at the beginning of
Tutorial 1, it created a default URLconf in <tt class="docutils literal"><span class="pre">mysite/urls.py</span></tt>. It also
automatically set your <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#setting-ROOT_URLCONF"><tt class="xref docutils literal"><span class="pre">ROOT_URLCONF</span></tt></a> setting (in <tt class="docutils literal"><span class="pre">settings.py</span></tt>) to
point at that file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">ROOT_URLCONF</span> <span class="o">=</span> <span class="s">'mysite.urls'</span>
</pre></div>
</div>
<p>Time for an example. Edit <tt class="docutils literal"><span class="pre">mysite/urls.py</span></tt> so it looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">django.conf.urls.defaults</span> <span class="k">import</span> <span class="o">*</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">''</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r'^polls/$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.index'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.detail'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/results/$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.results'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/vote/$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.vote'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^admin/'</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">urls</span><span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>This is worth a review. When somebody requests a page from your Web site -- say,
"/polls/23/", Django will load this Python module, because it's pointed to by
the <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#setting-ROOT_URLCONF"><tt class="xref docutils literal"><span class="pre">ROOT_URLCONF</span></tt></a> setting. It finds the variable named <tt class="docutils literal"><span class="pre">urlpatterns</span></tt>
and traverses the regular expressions in order. When it finds a regular
expression that matches -- <tt class="docutils literal"><span class="pre">r'^polls/(?P&lt;poll_id&gt;\d+)/$'</span></tt> -- it loads the
associated Python package/module: <tt class="docutils literal"><span class="pre">mysite.polls.views.detail</span></tt>. That
corresponds to the function <tt class="docutils literal"><span class="pre">detail()</span></tt> in <tt class="docutils literal"><span class="pre">mysite/polls/views.py</span></tt>. Finally,
it calls that <tt class="docutils literal"><span class="pre">detail()</span></tt> function like so:</p>
<div class="highlight-python"><pre>detail(request=&lt;HttpRequest object&gt;, poll_id='23')</pre>
</div>
<p>The <tt class="docutils literal"><span class="pre">poll_id='23'</span></tt> part comes from <tt class="docutils literal"><span class="pre">(?P&lt;poll_id&gt;\d+)</span></tt>. Using parenthesis
around a pattern "captures" the text matched by that pattern and sends it as an
argument to the view function; the <tt class="docutils literal"><span class="pre">?P&lt;poll_id&gt;</span></tt> defines the name that will be
used to identify the matched pattern; and <tt class="docutils literal"><span class="pre">\d+</span></tt> is a regular expression to
match a sequence of digits (i.e., a number).</p>
<p>Because the URL patterns are regular expressions, there really is no limit on
what you can do with them. And there's no need to add URL cruft such as <tt class="docutils literal"><span class="pre">.php</span></tt>
-- unless you have a sick sense of humor, in which case you can do something
like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="s">r'^polls/latest\.php$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.index'</span><span class="p">),</span>
</pre></div>
</div>
<p>But, don't do that. It's silly.</p>
<p>Note that these regular expressions do not search GET and POST parameters, or
the domain name. For example, in a request to <tt class="docutils literal"><span class="pre">http://www.example.com/myapp/</span></tt>,
the URLconf will look for <tt class="docutils literal"><span class="pre">myapp/</span></tt>. In a request to
<tt class="docutils literal"><span class="pre">http://www.example.com/myapp/?page=3</span></tt>, the URLconf will look for <tt class="docutils literal"><span class="pre">myapp/</span></tt>.</p>
<p>If you need help with regular expressions, see <a class="reference external" href="http://en.wikipedia.org/wiki/Regular_expression">Wikipedia's entry</a> and the
<a class="reference external" href="http://docs.python.org/library/re.html">Python documentation</a>. Also, the O'Reilly book "Mastering Regular Expressions"
by Jeffrey Friedl is fantastic.</p>
<p>Finally, a performance note: these regular expressions are compiled the first
time the URLconf module is loaded. They're super fast.</p>
</div>
<div class="section" id="s-write-your-first-view">
<span id="write-your-first-view"></span><h2>Write your first view<a class="headerlink" href="#write-your-first-view" title="Permalink to this headline">¶</a></h2>
<p>Well, we haven't created any views yet -- we just have the URLconf. But let's
make sure Django is following the URLconf properly.</p>
<p>Fire up the Django development Web server:</p>
<div class="highlight-bash"><div class="highlight"><pre>python manage.py runserver
</pre></div>
</div>
<p>Now go to "<a class="reference external" href="http://localhost:8000/polls/">http://localhost:8000/polls/</a>" on your domain in your Web browser.
You should get a pleasantly-colored error page with the following message:</p>
<div class="highlight-python"><pre>ViewDoesNotExist at /polls/

Tried index in module mysite.polls.views. Error was: 'module'
object has no attribute 'index'</pre>
</div>
<p>This error happened because you haven't written a function <tt class="docutils literal"><span class="pre">index()</span></tt> in the
module <tt class="docutils literal"><span class="pre">mysite/polls/views.py</span></tt>.</p>
<p>Try "/polls/23/", "/polls/23/results/" and "/polls/23/vote/". The error
messages tell you which view Django tried (and failed to find, because you
haven't written any views yet).</p>
<p>Time to write the first view. Open the file <tt class="docutils literal"><span class="pre">mysite/polls/views.py</span></tt>
and put the following Python code in it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">django.http</span> <span class="k">import</span> <span class="n">HttpResponse</span>

<span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s">"Hello, world. You're at the poll index."</span><span class="p">)</span>
</pre></div>
</div>
<p>This is the simplest view possible. Go to "/polls/" in your browser, and you
should see your text.</p>
<p>Now add the following view. It's slightly different, because it takes an
argument (which, remember, is passed in from whatever was captured by the
regular expression in the URLconf):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">detail</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">poll_id</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s">"You're looking at poll </span><span class="si">%s</span><span class="s">."</span> <span class="o">%</span> <span class="n">poll_id</span><span class="p">)</span>
</pre></div>
</div>
<p>Take a look in your browser, at "/polls/34/". It'll display whatever ID you
provide in the URL.</p>
</div>
<div class="section" id="s-write-views-that-actually-do-something">
<span id="write-views-that-actually-do-something"></span><h2>Write views that actually do something<a class="headerlink" href="#write-views-that-actually-do-something" title="Permalink to this headline">¶</a></h2>
<p>Each view is responsible for doing one of two things: Returning an
<a title="django.http.HttpResponse" class="reference external" href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse"><tt class="xref docutils literal"><span class="pre">HttpResponse</span></tt></a> object containing the content for the
requested page, or raising an exception such as <tt class="xref docutils literal"><span class="pre">Http404</span></tt>. The
rest is up to you.</p>
<p>Your view can read records from a database, or not. It can use a template
system such as Django's -- or a third-party Python template system -- or not.
It can generate a PDF file, output XML, create a ZIP file on the fly, anything
you want, using whatever Python libraries you want.</p>
<p>All Django wants is that <a title="django.http.HttpResponse" class="reference external" href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse"><tt class="xref docutils literal"><span class="pre">HttpResponse</span></tt></a>. Or an exception.</p>
<p>Because it's convenient, let's use Django's own database API, which we covered
in <a class="reference external" href="http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01"><em>Tutorial 1</em></a>. Here's one stab at the <tt class="docutils literal"><span class="pre">index()</span></tt>
view, which displays the latest 5 poll questions in the system, separated by
commas, according to publication date:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">mysite.polls.models</span> <span class="k">import</span> <span class="n">Poll</span>
<span class="k">from</span> <span class="nn">django.http</span> <span class="k">import</span> <span class="n">HttpResponse</span>

<span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">latest_poll_list</span> <span class="o">=</span> <span class="n">Poll</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s">'-pub_date'</span><span class="p">)[:</span><span class="mf">5</span><span class="p">]</span>
    <span class="n">output</span> <span class="o">=</span> <span class="s">', '</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">p</span><span class="o">.</span><span class="n">question</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">latest_poll_list</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>
</pre></div>
</div>
<p>There's a problem here, though: The page's design is hard-coded in the view. If
you want to change the way the page looks, you'll have to edit this Python code.
So let's use Django's template system to separate the design from Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">django.template</span> <span class="k">import</span> <span class="n">Context</span><span class="p">,</span> <span class="n">loader</span>
<span class="k">from</span> <span class="nn">mysite.polls.models</span> <span class="k">import</span> <span class="n">Poll</span>
<span class="k">from</span> <span class="nn">django.http</span> <span class="k">import</span> <span class="n">HttpResponse</span>

<span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">latest_poll_list</span> <span class="o">=</span> <span class="n">Poll</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s">'-pub_date'</span><span class="p">)[:</span><span class="mf">5</span><span class="p">]</span>
    <span class="n">t</span> <span class="o">=</span> <span class="n">loader</span><span class="o">.</span><span class="n">get_template</span><span class="p">(</span><span class="s">'polls/index.html'</span><span class="p">)</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">Context</span><span class="p">({</span>
        <span class="s">'latest_poll_list'</span><span class="p">:</span> <span class="n">latest_poll_list</span><span class="p">,</span>
    <span class="p">})</span>
    <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">c</span><span class="p">))</span>
</pre></div>
</div>
<p>That code loads the template called "polls/index.html" and passes it a context.
The context is a dictionary mapping template variable names to Python objects.</p>
<p>Reload the page. Now you'll see an error:</p>
<div class="highlight-python"><pre>TemplateDoesNotExist at /polls/
polls/index.html</pre>
</div>
<p>Ah. There's no template yet. First, create a directory, somewhere on your
filesystem, whose contents Django can access. (Django runs as whatever user your
server runs.) Don't put them under your document root, though. You probably
shouldn't make them public, just for security's sake.
Then edit <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#setting-TEMPLATE_DIRS"><tt class="xref docutils literal"><span class="pre">TEMPLATE_DIRS</span></tt></a> in your <tt class="docutils literal"><span class="pre">settings.py</span></tt> to tell Django where
it can find templates -- just as you did in the "Customize the admin look and
feel" section of Tutorial 2.</p>
<p>When you've done that, create a directory <tt class="docutils literal"><span class="pre">polls</span></tt> in your template directory.
Within that, create a file called <tt class="docutils literal"><span class="pre">index.html</span></tt>. Note that our
<tt class="docutils literal"><span class="pre">loader.get_template('polls/index.html')</span></tt> code from above maps to
"[template_directory]/polls/index.html" on the filesystem.</p>
<p>Put the following code in that template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">if</span> <span class="nv">latest_poll_list</span> <span class="cp">%}</span>
    <span class="nt">&lt;ul&gt;</span>
    <span class="cp">{%</span> <span class="k">for</span> <span class="nv">poll</span> <span class="k">in</span> <span class="nv">latest_poll_list</span> <span class="cp">%}</span>
        <span class="nt">&lt;li&gt;</span><span class="cp">{{</span> <span class="nv">poll.question</span> <span class="cp">}}</span><span class="nt">&lt;/li&gt;</span>
    <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
    <span class="nt">&lt;/ul&gt;</span>
<span class="cp">{%</span> <span class="k">else</span> <span class="cp">%}</span>
    <span class="nt">&lt;p&gt;</span>No polls are available.<span class="nt">&lt;/p&gt;</span>
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Load the page in your Web browser, and you should see a bulleted-list
containing the "What's up" poll from Tutorial 1.</p>
<div class="section" id="s-a-shortcut-render-to-response">
<span id="a-shortcut-render-to-response"></span><h3>A shortcut: render_to_response()<a class="headerlink" href="#a-shortcut-render-to-response" title="Permalink to this headline">¶</a></h3>
<p>It's a very common idiom to load a template, fill a context and return an
<a title="django.http.HttpResponse" class="reference external" href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse"><tt class="xref docutils literal"><span class="pre">HttpResponse</span></tt></a> object with the result of the rendered
template. Django provides a shortcut. Here's the full <tt class="docutils literal"><span class="pre">index()</span></tt> view,
rewritten:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">django.shortcuts</span> <span class="k">import</span> <span class="n">render_to_response</span>
<span class="k">from</span> <span class="nn">mysite.polls.models</span> <span class="k">import</span> <span class="n">Poll</span>

<span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">latest_poll_list</span> <span class="o">=</span> <span class="n">Poll</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s">'-pub_date'</span><span class="p">)[:</span><span class="mf">5</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">'polls/index.html'</span><span class="p">,</span> <span class="p">{</span><span class="s">'latest_poll_list'</span><span class="p">:</span> <span class="n">latest_poll_list</span><span class="p">})</span>
</pre></div>
</div>
<p>Note that once we've done this in all these views, we no longer need to import
<tt class="xref docutils literal"><span class="pre">loader</span></tt>, <tt class="xref docutils literal"><span class="pre">Context</span></tt> and
<a title="django.http.HttpResponse" class="reference external" href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse"><tt class="xref docutils literal"><span class="pre">HttpResponse</span></tt></a>.</p>
<p>The <a title="django.shortcuts.render_to_response" class="reference external" href="http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.render_to_response"><tt class="xref docutils literal"><span class="pre">render_to_response()</span></tt></a> function takes a template name
as its first argument and a dictionary as its optional second argument. It
returns an <a title="django.http.HttpResponse" class="reference external" href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse"><tt class="xref docutils literal"><span class="pre">HttpResponse</span></tt></a> object of the given template
rendered with the given context.</p>
</div>
</div>
<div class="section" id="s-raising-404">
<span id="raising-404"></span><h2>Raising 404<a class="headerlink" href="#raising-404" title="Permalink to this headline">¶</a></h2>
<p>Now, let's tackle the poll detail view -- the page that displays the question
for a given poll. Here's the view:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">django.http</span> <span class="k">import</span> <span class="n">Http404</span>
<span class="c"># ...</span>
<span class="k">def</span> <span class="nf">detail</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">poll_id</span><span class="p">):</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">Poll</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">poll_id</span><span class="p">)</span>
    <span class="k">except</span> <span class="n">Poll</span><span class="o">.</span><span class="n">DoesNotExist</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">Http404</span>
    <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">'polls/detail.html'</span><span class="p">,</span> <span class="p">{</span><span class="s">'poll'</span><span class="p">:</span> <span class="n">p</span><span class="p">})</span>
</pre></div>
</div>
<p>The new concept here: The view raises the <tt class="xref docutils literal"><span class="pre">Http404</span></tt> exception
if a poll with the requested ID doesn't exist.</p>
<p>We'll discuss what you could put in that <tt class="docutils literal"><span class="pre">polls/detail.html</span></tt> template a bit
later, but if you'd like to quickly get the above example working, just:</p>
<div class="highlight-python"><pre>{{ poll }}</pre>
</div>
<p>will get you started for now.</p>
<div class="section" id="s-a-shortcut-get-object-or-404">
<span id="a-shortcut-get-object-or-404"></span><h3>A shortcut: get_object_or_404()<a class="headerlink" href="#a-shortcut-get-object-or-404" title="Permalink to this headline">¶</a></h3>
<p>It's a very common idiom to use <tt class="xref docutils literal"><span class="pre">get()</span></tt> and raise
<tt class="xref docutils literal"><span class="pre">Http404</span></tt> if the object doesn't exist. Django provides a
shortcut. Here's the <tt class="docutils literal"><span class="pre">detail()</span></tt> view, rewritten:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">django.shortcuts</span> <span class="k">import</span> <span class="n">render_to_response</span><span class="p">,</span> <span class="n">get_object_or_404</span>
<span class="c"># ...</span>
<span class="k">def</span> <span class="nf">detail</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">poll_id</span><span class="p">):</span>
    <span class="n">p</span> <span class="o">=</span> <span class="n">get_object_or_404</span><span class="p">(</span><span class="n">Poll</span><span class="p">,</span> <span class="n">pk</span><span class="o">=</span><span class="n">poll_id</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">'polls/detail.html'</span><span class="p">,</span> <span class="p">{</span><span class="s">'poll'</span><span class="p">:</span> <span class="n">p</span><span class="p">})</span>
</pre></div>
</div>
<p>The <a title="django.shortcuts.get_object_or_404" class="reference external" href="http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.get_object_or_404"><tt class="xref docutils literal"><span class="pre">get_object_or_404()</span></tt></a> function takes a Django model
module as its first argument and an arbitrary number of keyword arguments, which
it passes to the module's <tt class="xref docutils literal"><span class="pre">get()</span></tt> function. It
raises <tt class="xref docutils literal"><span class="pre">Http404</span></tt> if the object doesn't exist.</p>
<div class="admonition-philosophy admonition">
<p class="first admonition-title">Philosophy</p>
<p>Why do we use a helper function <a title="django.shortcuts.get_object_or_404" class="reference external" href="http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.get_object_or_404"><tt class="xref docutils literal"><span class="pre">get_object_or_404()</span></tt></a>
instead of automatically catching the
<tt class="xref docutils literal"><span class="pre">ObjectDoesNotExist</span></tt> exceptions at a higher
level, or having the model API raise <tt class="xref docutils literal"><span class="pre">Http404</span></tt> instead of
<tt class="xref docutils literal"><span class="pre">ObjectDoesNotExist</span></tt>?</p>
<p class="last">Because that would couple the model layer to the view layer. One of the
foremost design goals of Django is to maintain loose coupling.</p>
</div>
<p>There's also a <a title="django.shortcuts.get_list_or_404" class="reference external" href="http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.get_list_or_404"><tt class="xref docutils literal"><span class="pre">get_list_or_404()</span></tt></a> function, which works
just as <a title="django.shortcuts.get_object_or_404" class="reference external" href="http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.get_object_or_404"><tt class="xref docutils literal"><span class="pre">get_object_or_404()</span></tt></a> -- except using
<tt class="xref docutils literal"><span class="pre">filter()</span></tt> instead of
<tt class="xref docutils literal"><span class="pre">get()</span></tt>. It raises <tt class="xref docutils literal"><span class="pre">Http404</span></tt> if
the list is empty.</p>
</div>
</div>
<div class="section" id="s-write-a-404-page-not-found-view">
<span id="write-a-404-page-not-found-view"></span><h2>Write a 404 (page not found) view<a class="headerlink" href="#write-a-404-page-not-found-view" title="Permalink to this headline">¶</a></h2>
<p>When you raise <tt class="xref docutils literal"><span class="pre">Http404</span></tt> from within a view, Django will load
a special view devoted to handling 404 errors. It finds it by looking for the
variable <tt class="docutils literal"><span class="pre">handler404</span></tt>, which is a string in Python dotted syntax -- the same
format the normal URLconf callbacks use. A 404 view itself has nothing special:
It's just a normal view.</p>
<p>You normally won't have to bother with writing 404 views. By default, URLconfs
have the following line up top:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">from</span> <span class="nn">django.conf.urls.defaults</span> <span class="k">import</span> <span class="o">*</span>
</pre></div>
</div>
<p>That takes care of setting <tt class="docutils literal"><span class="pre">handler404</span></tt> in the current module. As you can see
in <tt class="docutils literal"><span class="pre">django/conf/urls/defaults.py</span></tt>, <tt class="docutils literal"><span class="pre">handler404</span></tt> is set to
<tt class="xref docutils literal"><span class="pre">django.views.defaults.page_not_found()</span></tt> by default.</p>
<p>Three more things to note about 404 views:</p>
<ul class="simple">
<li>If <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#setting-DEBUG"><tt class="xref docutils literal"><span class="pre">DEBUG</span></tt></a> is set to <tt class="xref docutils literal"><span class="pre">True</span></tt> (in your settings module) then your
404 view will never be used (and thus the <tt class="docutils literal"><span class="pre">404.html</span></tt> template will never
be rendered) because the traceback will be displayed instead.</li>
<li>The 404 view is also called if Django doesn't find a match after checking
every regular expression in the URLconf.</li>
<li>If you don't define your own 404 view -- and simply use the default, which
is recommended -- you still have one obligation: To create a <tt class="docutils literal"><span class="pre">404.html</span></tt>
template in the root of your template directory. The default 404 view will
use that template for all 404 errors.</li>
<li>If <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#setting-DEBUG"><tt class="xref docutils literal"><span class="pre">DEBUG</span></tt></a> is set to <tt class="xref docutils literal"><span class="pre">False</span></tt> (in your settings module) and if
you didn't create a <tt class="docutils literal"><span class="pre">404.html</span></tt> file, an <tt class="docutils literal"><span class="pre">Http500</span></tt> is raised instead.
So remember to create a <tt class="docutils literal"><span class="pre">404.html</span></tt>.</li>
</ul>
</div>
<div class="section" id="s-write-a-500-server-error-view">
<span id="write-a-500-server-error-view"></span><h2>Write a 500 (server error) view<a class="headerlink" href="#write-a-500-server-error-view" title="Permalink to this headline">¶</a></h2>
<p>Similarly, URLconfs may define a <tt class="docutils literal"><span class="pre">handler500</span></tt>, which points to a view to call
in case of server errors. Server errors happen when you have runtime errors in
view code.</p>
</div>
<div class="section" id="s-use-the-template-system">
<span id="use-the-template-system"></span><h2>Use the template system<a class="headerlink" href="#use-the-template-system" title="Permalink to this headline">¶</a></h2>
<p>Back to the <tt class="docutils literal"><span class="pre">detail()</span></tt> view for our poll application. Given the context
variable <tt class="docutils literal"><span class="pre">poll</span></tt>, here's what the "polls/detail.html" template might look
like:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;h1&gt;</span><span class="cp">{{</span> <span class="nv">poll.question</span> <span class="cp">}}</span><span class="nt">&lt;/h1&gt;</span>
<span class="nt">&lt;ul&gt;</span>
<span class="cp">{%</span> <span class="k">for</span> <span class="nv">choice</span> <span class="k">in</span> <span class="nv">poll.choice_set.all</span> <span class="cp">%}</span>
    <span class="nt">&lt;li&gt;</span><span class="cp">{{</span> <span class="nv">choice.choice</span> <span class="cp">}}</span><span class="nt">&lt;/li&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="nt">&lt;/ul&gt;</span>
</pre></div>
</div>
<p>The template system uses dot-lookup syntax to access variable attributes. In
the example of <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">poll.question</span> <span class="pre">}}</span></tt>, first Django does a dictionary lookup
on the object <tt class="docutils literal"><span class="pre">poll</span></tt>. Failing that, it tries attribute lookup -- which works,
in this case. If attribute lookup had failed, it would've tried calling the
method <tt class="docutils literal"><span class="pre">question()</span></tt> on the poll object.</p>
<p>Method-calling happens in the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">for</span> <span class="pre">%}</span></tt> loop: <tt class="docutils literal"><span class="pre">poll.choice_set.all</span></tt> is
interpreted as the Python code <tt class="docutils literal"><span class="pre">poll.choice_set.all()</span></tt>, which returns an
iterable of Choice objects and is suitable for use in the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">for</span> <span class="pre">%}</span></tt> tag.</p>
<p>See the <a class="reference external" href="http://docs.djangoproject.com/en/dev/topics/templates/#topics-templates"><em>template guide</em></a> for more about templates.</p>
</div>
<div class="section" id="s-simplifying-the-urlconfs">
<span id="simplifying-the-urlconfs"></span><h2>Simplifying the URLconfs<a class="headerlink" href="#simplifying-the-urlconfs" title="Permalink to this headline">¶</a></h2>
<p>Take some time to play around with the views and template system. As you edit
the URLconf, you may notice there's a fair bit of redundancy in it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">''</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r'^polls/$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.index'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.detail'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/results/$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.results'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/vote/$'</span><span class="p">,</span> <span class="s">'mysite.polls.views.vote'</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Namely, <tt class="docutils literal"><span class="pre">mysite.polls.views</span></tt> is in every callback.</p>
<p>Because this is a common case, the URLconf framework provides a shortcut for
common prefixes. You can factor out the common prefixes and add them as the
first argument to <tt class="xref docutils literal"><span class="pre">patterns()</span></tt>, like so:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">'mysite.polls.views'</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r'^polls/$'</span><span class="p">,</span> <span class="s">'index'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/$'</span><span class="p">,</span> <span class="s">'detail'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/results/$'</span><span class="p">,</span> <span class="s">'results'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^polls/(?P&lt;poll_id&gt;\d+)/vote/$'</span><span class="p">,</span> <span class="s">'vote'</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>This is functionally identical to the previous formatting. It's just a bit
tidier.</p>
</div>
<div class="section" id="s-decoupling-the-urlconfs">
<span id="decoupling-the-urlconfs"></span><h2>Decoupling the URLconfs<a class="headerlink" href="#decoupling-the-urlconfs" title="Permalink to this headline">¶</a></h2>
<p>While we're at it, we should take the time to decouple our poll-app URLs from
our Django project configuration. Django apps are meant to be pluggable -- that
is, each particular app should be transferable to another Django installation
with minimal fuss.</p>
<p>Our poll app is pretty decoupled at this point, thanks to the strict directory
structure that <tt class="docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">startapp</span></tt> created, but one part of it is
coupled to the Django settings: The URLconf.</p>
<p>We've been editing the URLs in <tt class="docutils literal"><span class="pre">mysite/urls.py</span></tt>, but the URL design of an
app is specific to the app, not to the Django installation -- so let's move the
URLs within the app directory.</p>
<p>Copy the file <tt class="docutils literal"><span class="pre">mysite/urls.py</span></tt> to <tt class="docutils literal"><span class="pre">mysite/polls/urls.py</span></tt>. Then, change
<tt class="docutils literal"><span class="pre">mysite/urls.py</span></tt> to remove the poll-specific URLs and insert an
<tt class="xref docutils literal"><span class="pre">include()</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="s">r'^polls/'</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s">'mysite.polls.urls'</span><span class="p">)),</span>
</pre></div>
</div>
<p><tt class="xref docutils literal"><span class="pre">include()</span></tt>, simply, references another URLconf.
Note that the regular expression doesn't have a <tt class="docutils literal"><span class="pre">$</span></tt> (end-of-string match
character) but has the trailing slash. Whenever Django encounters
<tt class="xref docutils literal"><span class="pre">include()</span></tt>, it chops off whatever part of the
URL matched up to that point and sends the remaining string to the included
URLconf for further processing.</p>
<p>Here's what happens if a user goes to "/polls/34/" in this system:</p>
<ul class="simple">
<li>Django will find the match at <tt class="docutils literal"><span class="pre">'^polls/'</span></tt></li>
<li>Then, Django will strip off the matching text (<tt class="docutils literal"><span class="pre">"polls/"</span></tt>) and send the
remaining text -- <tt class="docutils literal"><span class="pre">"34/"</span></tt> -- to the 'mysite.polls.urls' URLconf for
further processing.</li>
</ul>
<p>Now that we've decoupled that, we need to decouple the 'mysite.polls.urls'
URLconf by removing the leading "polls/" from each line:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">'mysite.polls.views'</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r'^$'</span><span class="p">,</span> <span class="s">'index'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^(?P&lt;poll_id&gt;\d+)/$'</span><span class="p">,</span> <span class="s">'detail'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^(?P&lt;poll_id&gt;\d+)/results/$'</span><span class="p">,</span> <span class="s">'results'</span><span class="p">),</span>
    <span class="p">(</span><span class="s">r'^(?P&lt;poll_id&gt;\d+)/vote/$'</span><span class="p">,</span> <span class="s">'vote'</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The idea behind <tt class="xref docutils literal"><span class="pre">include()</span></tt> and URLconf
decoupling is to make it easy to plug-and-play URLs. Now that polls are in their
own URLconf, they can be placed under "/polls/", or under "/fun_polls/", or
under "/content/polls/", or any other URL root, and the app will still work.</p>
<p>All the poll app cares about is its relative URLs, not its absolute URLs.</p>
<p>When you're comfortable with writing views, read <a class="reference external" href="http://docs.djangoproject.com/en/dev/intro/tutorial04/#intro-tutorial04"><em>part 4 of this tutorial</em></a> to learn about simple form processing and generic views.</p>
</div>
</div>



<div id="content-secondary">
  <h2 id="comments">Questions/Feedback</h2>
  <p>Having trouble? We'd like to help!</p>
  <ul>
    <li>
      Try the <a href="http://docs.djangoproject.com/en/dev/faq/">FAQ</a> — it's got answers to many common
      questions.
    </li>
    <li>
      Search for information in the <a href="http://groups.google.com/group/django-users/">archives of the
      django-users mailing list</a>, or <a href="http://groups.google.com/group/django-users/">post a question</a>.
    </li>
    <li>
      Ask a question in the <a href="irc://irc.freenode.net/">#django IRC
      channel</a>, or search the <a href="http://oebfare.com/logger/django/">IRC
      logs</a> to see if its been asked before.
    </li>
    <li>
      If you notice errors with this documentation, please <a href="http://code.djangoproject.com/simpleticket?component=Documentation">
      open a ticket</a> and let us know! Please only use the ticket tracker for
      criticisms and improvements on the docs. For tech support, use the
      resources above.
    </li>
  </ul>
</div>

		</div>
		<!-- END #content-main -->
		<div id="content-related" class="sidebar">
		
  
    <h2>Contents</h2>
    
      <ul>
<li><a class="reference external" href="">Writing your first Django app, part 3</a><ul>
<li><a class="reference external" href="#philosophy">Philosophy</a></li>
<li><a class="reference external" href="#design-your-urls">Design your URLs</a></li>
<li><a class="reference external" href="#write-your-first-view">Write your first view</a></li>
<li><a class="reference external" href="#write-views-that-actually-do-something">Write views that actually do something</a><ul>
<li><a class="reference external" href="#a-shortcut-render-to-response">A shortcut: render_to_response()</a></li>
</ul>
</li>
<li><a class="reference external" href="#raising-404">Raising 404</a><ul>
<li><a class="reference external" href="#a-shortcut-get-object-or-404">A shortcut: get_object_or_404()</a></li>
</ul>
</li>
<li><a class="reference external" href="#write-a-404-page-not-found-view">Write a 404 (page not found) view</a></li>
<li><a class="reference external" href="#write-a-500-server-error-view">Write a 500 (server error) view</a></li>
<li><a class="reference external" href="#use-the-template-system">Use the template system</a></li>
<li><a class="reference external" href="#simplifying-the-urlconfs">Simplifying the URLconfs</a></li>
<li><a class="reference external" href="#decoupling-the-urlconfs">Decoupling the URLconfs</a></li>
</ul>
</li>
</ul>

    
  
  
  
    <h2>Search</h2>
    
    <form action="/en/dev/search/" id="search" class="search">
  <div>
    <input name="cx" value="009763561546736975936:e88ek0eurf4" type="hidden">
    <input name="cof" value="FORID:11" type="hidden">
    <input name="ie" value="UTF-8" type="hidden">
    <input name="hl" value="" type="hidden">
    <input style="background: rgb(255, 255, 255) url(http://www.google.com/coop/intl/en/images/google_custom_search_watermark.gif) no-repeat scroll left center; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" id="id_search_q" class="query" name="q" type="text">
    <input name="sa" class="submit" value="Search" type="submit">
    <ul>
<li><label for="id_search_as_q_0"><input checked="checked" id="id_search_as_q_0" value="more:dev_docs" name="as_q" type="radio"> Latest</label></li>
<li><label for="id_search_as_q_1"><input id="id_search_as_q_1" value="more:1.0_docs" name="as_q" type="radio"> 1.0</label></li>
<li><label for="id_search_as_q_2"><input id="id_search_as_q_2" value="more:0.96_docs" name="as_q" type="radio"> 0.96</label></li>
<li><label for="id_search_as_q_3"><input id="id_search_as_q_3" value="more:all_docs" name="as_q" type="radio"> All</label></li>
</ul>
  </div>
</form>
<script type="text/javascript" src="Django%20%7C%20Writing%20your%20first%20Django%20app,%20part%203%20%7C%20Django%20Documentation_files/brand.html"></script>
  
  
  
    <h2>Browse</h2>
    <ul>
      
        
          <li>Prev: <a href="http://docs.djangoproject.com/en/dev/intro/tutorial02/">Writing your first Django app, part 2</a></li>
        
        
          <li>Next: <a href="http://docs.djangoproject.com/en/dev/intro/tutorial04/">Writing your first Django app, part 4</a></li>
        
        <li><a href="http://docs.djangoproject.com/en/dev/contents/">Table of contents</a></li>
        
          <li><a href="http://docs.djangoproject.com/en/dev/genindex/">General Index</a></li>
        
          <li><a href="http://docs.djangoproject.com/en/dev/modindex/">Global Module Index</a></li>
        
      
    </ul>
  
  
  
    <h2>You are here:</h2>
    <ul>
      
        <li>
          <a href="http://docs.djangoproject.com/en/dev/">Django dev documentation</a>
          
            <ul><li><a href="http://docs.djangoproject.com/en/dev/intro/">Getting started</a>
          
          <ul><li>Writing your first Django app, part 3</li></ul>
          </li></ul>
        </li>
      
    </ul>
  
  
  
    <h3>Last update:</h3>
    <div>May 23, 2009, 8 a.m. (<a href="http://www.timeanddate.com/worldclock/city.html?n=64">CDT</a>)</div>
  

		</div>
		<!-- END #content-related -->

		</div>
		<!-- END #content -->
		<div id="footer">
			<p>© 2005-2009 <a href="http://www.djangoproject.com/foundation/">Django Software Foundation</a> unless otherwise noted. Django is a registered trademark of the Django Software Foundation. 
			Hosting graciously provided by <a href="http://mediatemple.net/">
			<img style="vertical-align: middle; position: relative; top: -1px;" src="Django%20%7C%20Writing%20your%20first%20Django%20app,%20part%203%20%7C%20Django%20Documentation_files/mt.png" alt="media temple"></a>
			</p>
		</div>
		<!-- END #footer -->
	</div>
	<!-- END #container -->
	</body></html>